﻿<UserControl 
    x:Class="Sidvall.UI.Uwp.Controls.SecurityControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Sidvall.UI.Uwp.Controls"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:vms="using:Sidvall.UI.ViewModels"
    xmlns:converters="using:Sidvall.UI.Uwp.Converters" 
    xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls"
    mc:Ignorable="d"
    d:DesignHeight="300"
    d:DesignWidth="400">

    <UserControl.Resources>
        <converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
        <converters:InverseBooleanConverter x:Key="InverseBooleanConverter"/>
    </UserControl.Resources>

    <Grid d:DataContext="{d:DesignInstance vms:SecurityControlViewModel, IsDesignTimeCreatable=True}">
        <Grid>
            <Pivot x:Name="TabControl" BorderThickness="0" Padding="0" IsEnabled="{Binding IsBusy, Converter={StaticResource InverseBooleanConverter}, Mode=OneWay}">
                <PivotItem Margin="0,-48,0,0">
                    <Grid>
                        <TextBlock Text="{Binding ResourceKeyManager.SecurityControlLogOffMessage}" HorizontalAlignment="Center" VerticalAlignment="Center" />
                    </Grid>
                </PivotItem>
                <PivotItem Margin="0,-48,0,0">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>

                        <StackPanel>
                            <StackPanel Margin="8">
                                <TextBlock Text="{Binding ResourceKeyManager.SecurityControlUserName}"/>
                                <TextBox x:Name="UserNameBox" Grid.Column="1" Text="{Binding UserName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" VerticalContentAlignment="Center" 
                                         Height="30" Padding="5,0" KeyDown="LogOnControl_KeyDown" />
                            </StackPanel>
                            <StackPanel Margin="8">
                                <TextBlock Text="{Binding ResourceKeyManager.SecurityControlPassword}"/>
                                <PasswordBox x:Name="PasswordBox" Grid.Column="1" VerticalContentAlignment="Center" Height="30" Padding="5,0" 
                                             KeyDown="LogOnControl_KeyDown" />
                            </StackPanel>
                            <Grid Margin="8">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition />
                                    <ColumnDefinition />
                                </Grid.ColumnDefinitions>

                                <CheckBox Content="{Binding ResourceKeyManager.SecurityControlRememberMe}" IsChecked="{Binding RememberMe, Mode=TwoWay}" 
                                          KeyDown="LogOnControl_KeyDown" />
                                <HyperlinkButton Grid.Column="1" HorizontalAlignment="Right" Content="{Binding ResourceKeyManager.SecurityControlResetPasswordButton}" 
                                                 Click="ChangePassword_Click" />
                            </Grid>
                            <StackPanel Margin="8">
                            </StackPanel>
                        </StackPanel>
                    </Grid>
                </PivotItem>
                <PivotItem Margin="0,-48,0,0">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>

                        <StackPanel Margin="8">
                            <StackPanel>
                                <TextBlock Text="{Binding ResourceKeyManager.SecurityControlSecurityCode}"/>
                                <TextBox x:Name="CodeBox" Grid.Column="1" Text="{Binding Code, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" VerticalContentAlignment="Center" Height="30" Padding="5,0" />
                            </StackPanel>
                        </StackPanel>
                    </Grid>
                </PivotItem>
                <PivotItem Margin="0,-48,0,0">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>

                        <StackPanel>
                            <StackPanel Margin="8">
                                <TextBlock Text="{Binding ResourceKeyManager.SecurityControlResetPasswordUserName}"/>
                                <TextBox x:Name="EmailBox" Grid.Column="1" Text="{Binding Email, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" VerticalContentAlignment="Center" Height="30" />
                            </StackPanel>
                            <StackPanel Margin="8">
                                <HyperlinkButton Content="{Binding ResourceKeyManager.SecurityControlBackButton}" Click="GotoLogOn_Click" />
                            </StackPanel>
                        </StackPanel>
                    </Grid>
                </PivotItem>
                <PivotItem Margin="0,-48,0,0">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>

                        <TextBox Margin="8" TextWrapping="Wrap" IsReadOnly="True" ScrollViewer.VerticalScrollBarVisibility="Auto"
                                    Text="{Binding ResourceKeyManager.SecurityControlResetPasswordMessage, Mode=OneWay}" />
                    </Grid>
                </PivotItem>
            </Pivot>
        </Grid>
        <controls:Loading HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Background="CadetBlue" Opacity="0.75" IsLoading="{Binding IsBusy}">
            <StackPanel Orientation="Horizontal" Padding="12">
                <ProgressRing IsActive="True" Margin="0,0,12,0" />
                <TextBlock Text="{Binding IsBusyMessage}" VerticalAlignment="Center" />
            </StackPanel>
        </controls:Loading>
    </Grid>
</UserControl>
